﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using MySql.Data.MySqlClient;

namespace MovieSystem.Banco
{
    public class EntSala
    {
        private int intSalaId = 0;
        private string strDescricaoSala = "";
        private int intQtdCadeiraHorizaontal = 0;
        private int intQtdCadeiraVertical = 0;
        private int intQtdCadeirasSala = 0;

        /// <summary>
        /// Id
        /// </summary>
        public int Id
        {

            get { return intSalaId; }
            set { intSalaId = value; }

        }

        public string Descricao
        {

            get { return strDescricaoSala; }
            set { strDescricaoSala = value; }

        }

        public int QtdCadeiraHorizaontal
        {

            get { return intQtdCadeiraHorizaontal; }
            set { intQtdCadeiraHorizaontal = value; }

        }

        public int QtdCadeiraVertical
        {

            get { return intQtdCadeiraVertical; }
            set { intQtdCadeiraVertical = value; }

        }
        public int QtdCadeirasSala
        {

            get { return intQtdCadeirasSala; }
            set { intQtdCadeirasSala = value; }

        }

        public Boolean Inserir()
        {

            int intNumero = 0;
            if (EntConexao.AbrirConexao())
            {
                MySqlCommand commS = new MySqlCommand("Insert into sala (descricaoSala, fileiraHorizSala, fileiraVertSala, poltronaSala) values ('" + this.Descricao + "', " + this.QtdCadeiraHorizaontal + ", " + this.QtdCadeiraVertical + ", " + this.QtdCadeirasSala + ");", EntConexao.bdConn);
                intNumero = commS.ExecuteNonQuery();

                EntConexao.FecharConexao();

            }


            return true;

        }

        public Boolean Alterar()
        {

            int intNumero = 0;
            if (EntConexao.AbrirConexao())
            {
                MySqlCommand commS = new MySqlCommand("update sala set descricaoSala= '" + this.Descricao + "', fileiraHorizSala = " + this.QtdCadeiraHorizaontal + ", fileiraVertSala = " + this.QtdCadeiraVertical + ", poltronaSala = " + this.QtdCadeirasSala + " where idSala = " + this.Id + ";", EntConexao.bdConn);
                intNumero = commS.ExecuteNonQuery();

                EntConexao.FecharConexao();

            }


            return true;

        }

        public Boolean Excluir()
        {

            int intNumero = 0;
            if (EntConexao.AbrirConexao())
            {
                MySqlCommand commS = new MySqlCommand("delete from sala where idSala = " + this.Id + ";", EntConexao.bdConn);
                intNumero = commS.ExecuteNonQuery();

                EntConexao.FecharConexao();

            }


            return true;

        }

        public EntSala BuscaPorId(string parametro)
        {
            EntSala oSala = new EntSala();

            if (EntConexao.AbrirConexao())
            {
                MySqlCommand commS = new MySqlCommand("SELECT * FROM sala where idSala =" + parametro + "", EntConexao.bdConn);
                MySqlDataReader reader = commS.ExecuteReader();

                while (reader.Read())
                {
                    oSala = new EntSala();
                    oSala.Id = Convert.ToInt32(reader["idSala"].ToString());
                    oSala.Descricao = reader["descricaoSala"].ToString();
                    oSala.QtdCadeiraHorizaontal = Convert.ToInt32(reader["fileiraHorizSala"].ToString());
                    oSala.QtdCadeiraVertical = Convert.ToInt32(reader["fileiraVertSala"].ToString());
                    oSala.QtdCadeirasSala = Convert.ToInt32(reader["poltronaSala"].ToString());

                }

                EntConexao.FecharConexao();
            }
            return oSala;
        }

        public List<EntSala> BuscaPorParametro(string parametro)
        {
            List<EntSala> lSalas = new List<EntSala>();

            if (EntConexao.AbrirConexao())
            {
                MySqlCommand commS = new MySqlCommand("SELECT * FROM sala where descricao ='" + parametro + "'", EntConexao.bdConn);
                MySqlDataReader reader = commS.ExecuteReader();

                while (reader.Read())
                {
                    EntSala oSala = new EntSala();
                    oSala.Id = Convert.ToInt32(reader["idSala"].ToString());
                    oSala.Descricao = reader["descricaoSala"].ToString();
                    oSala.QtdCadeiraHorizaontal = Convert.ToInt32(reader["fileiraHorizSala"].ToString());
                    oSala.QtdCadeiraVertical = Convert.ToInt32(reader["fileiraVertSala"].ToString());
                    oSala.QtdCadeirasSala = Convert.ToInt32(reader["poltronaSala"].ToString());
                    lSalas.Add(oSala);
                }

                EntConexao.FecharConexao();
            }
            return lSalas;
        }

        public List<EntSala> BuscaTodas()
        {
            List<EntSala> lSalas = new List<EntSala>();

            if (EntConexao.AbrirConexao())
            {
                MySqlCommand commS = new MySqlCommand("SELECT * FROM sala;", EntConexao.bdConn);
                MySqlDataReader reader = commS.ExecuteReader();

                while (reader.Read())
                {
                    EntSala oSala = new EntSala();
                    oSala.Id = Convert.ToInt32(reader["idSala"].ToString());
                    oSala.Descricao = reader["descricaoSala"].ToString();
                    oSala.QtdCadeiraHorizaontal = Convert.ToInt32(reader["fileiraHorizSala"].ToString());
                    oSala.QtdCadeiraVertical = Convert.ToInt32(reader["fileiraVertSala"].ToString());
                    oSala.QtdCadeirasSala = Convert.ToInt32(reader["poltronaSala"].ToString());
                    lSalas.Add(oSala);

                }

                EntConexao.FecharConexao();
            }
            return lSalas;
        }
    }
}
